<?php

namespace App\Models\Shop;

use App\Models\BaseModel;
use Illuminate\Http\Request;

/**
 * @title 厂价提货区模型
 * Class ShopGoodsSpecialModel
 * @package App\Models\Shop
 */
class ShopGoodsSpecialModel extends BaseModel
{
    protected $table = 'shop_goods_special';

    protected $primaryKey = 'goods_id';

    public $dateFormat = 'U';

    public function goods()
    {
        return $this->belongsTo('App\Models\Shop\ShopGoodsModel','goods_id','goods_id');
    }

    public function addPrice(Request $request,$goods_id)
    {
        $bill = self::findOrNew($goods_id);
        $bill->goods_id = $goods_id;
        $bill->price = $request->post('price');
        $bill->cost_price = $request->post('cost_price',0);
        $bill->market_price = $request->post('market_price',0);
        $bill->guide_price = $request->post('guide_price',0);
        $bill->price_up_float_ratio = $request->post('price_up_float_ratio',0);
        $bill->price_down_float_ratio = $request->post('price_down_float_ratio',0);
        $bill->self_credit_score = $request->post('self_credit_score',0);
        $bill->entrust_credit_score = $request->post('entrust_credit_score',0);
        $bill->entrust_back_ratio = $request->post('entrust_back_ratio',0);
        return $bill->save();
    }
}
